package cn.dhnep.demo.service.impl;

import cn.dhnep.demo.mapper.ClassifyMapper;
import cn.dhnep.demo.pojo.Classify;
import cn.dhnep.demo.pojo.vo.RespPageBean;
import cn.dhnep.demo.service.ClassifyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author dhn
 * @since 2021-08-16
 */
@Service
public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify> implements ClassifyService {

    @Override
    public RespPageBean pageQueryClassify(Integer current, Integer size, Integer fid, String number, String name) {
        QueryWrapper<Classify> wrapper = new QueryWrapper<>();

        if (!StringUtils.isEmpty(fid)) wrapper.eq("fid", fid); //产品类别
        if (!StringUtils.isEmpty(number)) wrapper.like("number", number); //产品编号
        if (!StringUtils.isEmpty(name)) wrapper.like("name", name); //产品名称
        wrapper.orderByAsc("id");

        Page<Classify> page = new Page<>(current, size); //分页数据
        baseMapper.selectPage(page, wrapper);
        return new RespPageBean(0, page.getTotal(), page.getRecords());
    }
}
